//
//  LoadingView.m
//  ios_news
//
//  Created by Han on 14-6-12.
//  Copyright (c) 2014年 ucoder. All rights reserved.
//

#import "LoadingView.h"

@implementation LoadingView
@synthesize indicator;

static int tagValue = 300;

+ (int)getViewTag
{
    return tagValue;
}



+ (id)add:(UIView *)superView initWithFrame:(CGRect)frame viewTag:(NSInteger) tag;
{

	LoadingView *loadingView =
    [[LoadingView alloc] initWithFrame:frame];
    
    if (tag == 0) {
        loadingView.tag = tag;
    }
    
    /*
    UIImageView *loadingImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 150, 100)];
    
    loadingImageView.image = [UIImage imageNamed:@"loading"];
    
    loadingImageView.center = loadingView.center;
    [loadingView addSubview:loadingImageView];
     
     
    
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(loadingImageView.frame.origin.x -40, loadingImageView.frame.origin.y+(100-30)/2-10, 30, 30)];
    */
    
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]init];
    
    indicator.center = CGPointMake(frame.size.width*0.5, frame.size.height*0.5);
    
    
    indicator.hidesWhenStopped = YES;
    indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    [loadingView addSubview:indicator];
    
    
    [indicator startAnimating];
    
    [superView addSubview:loadingView];
    
    return loadingView;
}


+ (void)add:(UIView *)superview viewTag:(NSInteger) tag
{
    
    
	LoadingView *loadingView =
    [[LoadingView alloc] initWithFrame:[superview bounds]];
    loadingView.tag = tag;
    
    
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    indicator.hidesWhenStopped = NO;
    indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    
    indicator.center = loadingView.center;
    [indicator startAnimating];
    
    [loadingView addSubview:indicator];
    
    
    
    
    /*
    UIImageView *loadingImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 150, 100)];
    
    loadingImageView.image = [UIImage imageNamed:@"loading"];
    
    loadingImageView.center = loadingView.center;
    [loadingView addSubview:loadingImageView];
    */
    
    [superview addSubview:loadingView];
    
    
}


- (void)remove
{
	//UIView *superview = [self superview];
	[super removeFromSuperview];
    
	// Set up the animation
	//CATransition *animation = [CATransition animation];
	//[animation setType:kCATransitionFade];
	
	//[[superview layer] addAnimation:animation forKey:@"layerAnimation"];
}

@end
